use super::*;

#[derive(Debug, Clone)]
pub struct Table<'a> {
	// fixed32	version	Version number of the glyph properties table. See table above for what each version means.
	pub version: i32,
	// uint16	format	Format of the glyph properties table, set to 0 if no lookup data is present; set to 1 if lookup data is present.
	pub format: u16,
	// uint16	default properties	Default properties applied to a glyph if that glyph is not present in the lookup table.
	pub default: u16,
	// variable	lookup data	Lookup table associating glyphs with their properties. See below for details on how to interpret the lookup values.
	pub lookup: Option<aat::Lookup<'a>>,
}
impl<'a> Table<'a> {
	pub fn parse(num_glyphs: u16, data: &'a [u8]) -> Option<Self> {
		let mut s = Stream::new(data);
		let version: i32 = s.read()?;
		let format: u16 = s.read()?;
		Some(Self {
			version,
			format,
			default: s.read()?,
			lookup: if format == 1 {
				aat::Lookup::parse(num_glyphs, s.tail()?)
			} else {
				None
			},
		})
	}
}

pub struct Property(pub u16);
impl Property {
	pub const FLOATER: u16 = 0x8000; // This glyph is a floater (for example a floating accent or vowel mark). NOTE: It is very important that this bit only be set for glyphs that have a zero advance width.
	pub const LEFT_EDGE: u16 = 0x4000; // This glyph can hang off the left edge of a horizontal line or the top edge of a vertical line.
	pub const RIGHT_EDGE: u16 = 0x2000; // This glyph can hang off the right edge of a horizontal line or the bottom edge of a vertical line.
	pub const DIR_END: u16 = 0x1000; // If this property bit is on, and the glyph ends up in a right-to- left directional grouping, then the complementary bracketing glyph should be substituted for this glyph.
	pub const COMPLEMENT_MASK: u16 = 0x0F00; // These four bits give the offset to the complementary bracketing glyph (or zero if this glyph has no such complementary bracketing glyph).
	pub const ATTACH: u16 = 0x0080; // This glyph always attaches to the glyph appearing physically to the right of it. Note that this bit was added in version 2.0; it is invalid to set it in a version 1.0 glyph properties table.
	pub const RESERVED: u16 = 0x0060; // These two bits must be set to zero. This mask is reserved for future properties.
	pub const DIR_CLASS_MASK: u16 = 0x001F; // These five bits contain the glyph's directionality class. Note that in versions of Unicode prior to 3.0, only four of these bits are actually used.

	pub const STRONG_LR: u16 = 0; //Strong (left-to-right)
	pub const STRONG_RLNA: u16 = 1; // Strong (right-to-left, non-Arabic)
	pub const STRONG_RL: u16 = 2; // Arabic letters (right-to-left)
	pub const WEAK_EN: u16 = 3; // European number
	pub const WEAK_ENS: u16 = 4; //European number separator
	pub const WEAK_ENT: u16 = 5; //European number terminator
	pub const WEAK_AN: u16 = 6; //Arabic number
	pub const WEAK_CNS: u16 = 7; //Common number separator
	pub const NEUTRAL_BS: u16 = 8; //Block separator
	pub const NEUTRAL_SS: u16 = 9; //Segment separator
	pub const NEUTRAL_WS: u16 = 10; //Whitespace
	pub const NEUTRAL_O: u16 = 11; //Other neutrals
}
